package tpf.designer.pattern.course4.structure_pattern1.homework1;
import org.junit.Test;

import java.io.File;


public class Client {

    public static void createTree(AbstractNode node) throws Exception{
        File file = new File(node.name);
        File[] f = file.listFiles();
        for(File fi : f){
            if(fi.isFile()){
                VFile filer = new VFile(fi.getAbsolutePath());
                node.addNode(filer);
            }
            if(fi.isDirectory()){
                VFile noder = new VFile(fi.getAbsolutePath());
                node.addNode(noder);
                createTree(noder);//使用递归生成树结构
            }
        }
    }

    @Test
    public void test1(){
        AbstractNode noder = new VDirectory("/home/tpf/IdeaProjects/DesignPattern/target");
        try {
            createTree(noder);
        } catch (Exception e) {
            e.printStackTrace();
        }
        noder.display();
    }
}
